#ifndef _Screen_H_
#define _Screen_H_
#include <iostream>
#include <string>
using namespace std;
class Window_mgr;
class Screen{
friend class Window_mgr;
public:
	using pos=string::size_type;
	Screen()=default;
	Screen(pos ht,pos wd,char c):height(ht),width(wd),contents(ht*wd,c){}
	Screen(pos ht,pos wd):height(ht),width(wd),contents(""){}
	char get()const {return contents[cursor];}
	inline char get(pos ht,pos wd)const;
	Screen &move(pos r,pos c);
	Screen &set(char);
	Screen &set(pos,pos,char);
	Screen &display(ostream &os){do_display(os);return *this;}
	const Screen &display(ostream &os) const {do_display(os);return *this;}
private:
	pos cursor=0;
	pos height=0,width=0;
	string contents;
	void do_display(ostream &os)const {os<<contents;}
};
inline Screen &Screen::move(pos r,pos c)
{
	pos row=r*width;
	cursor=row+c;
	return *this;
}
char Screen::get(pos r,pos c)const
{
	pos row=r*width;
	return contents[row+c];
}
inline Screen &Screen::set(char c)
{
	contents[cursor]=c;
	return *this;
}
inline Screen &Screen::set(pos row,pos col,char ch)
{
	contents[row*width+col]=ch;
	return *this;
}
#endif
